<?php
/*
说明 : 这是登录 ajax 请求文件
*/

include '../../configs/global.php';
$data = $_POST;

$username = $data['username'];
$password = $data['password'];
$verify = $data['verify'];

// 定义一个返回数组
$ajax_res = array();

// 判断是否为空
if (!$username || !$password || !$verify) {
    $ajax_res['code'] = 300;
    $ajax_res['info'] = '填写的信息不完善';
    echo json_encode($ajax_res);
    exit;
}

// 判断验证码是否正确
// if($verify != $_SESSION['vverify']){
// 	$ajax_res['code']=300;
// 	$ajax_res['info']='验证码不正确';
// 	echo json_encode($ajax_res);
// 	exit;
// }

$sql = "select * from student where name='$username'";


$row = $pdo->getOne($sql);


if ($row) {
    if (md5($password) == $row['password']) {
        //添加 session 标识，用于判断是否登录
        $_SESSION['username'] = $username;
        $ajax_res['code'] = 200;
        $ajax_res['info'] = '登录成功';
    } else {
        $ajax_res['code'] = 300;
        $ajax_res['info'] = '输入信息有误';
    }
} else {
    $ajax_res['code'] = 300;
    $ajax_res['info'] = '输入信息有误';
}
echo json_encode($ajax_res);
